<template>
  <transition enter-active-class=" animated slideInRight" :duration="500" mode="in-out">
    <page-view class="detail" v-if="detailMovie">
      <m-header :back="true">电影详细信息</m-header>
      <div class="movieBox">
        <img :src="detailMovie.img.replace('w.h','128.180')" class="bgImg" alt />
        <div class="left">
          <img :src="detailMovie.img.replace('w.h','128.180')" alt />
          <span class="iconfont icon-bofang-yuanshijituantubiao" @click.stop="isShowVideo=true"></span>
        </div>
        <ul class="center">
          <li class="nm">{{detailMovie.nm}}</li>
          <li class="sc">
            <span>{{detailMovie.sc}}</span>
            ({{detailMovie.wish}}想看)
          </li>
          <li>{{detailMovie.cat}}</li>
          <li>{{detailMovie.dur}}分钟</li>
          <li>{{detailMovie.pubDesc}}</li>
        </ul>
        <div class="right">
          <span class="iconfont icon-right-arrow"></span>
        </div>
      </div>
      <div class="btnBuyDiv">
        <button type="button" class="btnBuy">我要购票</button>
      </div>
      <div class="dra" :class="[isShowAll==true?null:'hide']">{{detailMovie.dra}}</div>
      <div class="upAndDown" @click="isShowAll=!isShowAll">
        <span class="iconfont icon-icon_sanjiaoxing" :class="[isShowAll==true?'up':null]"></span>
      </div>
      <!-- 添加一个transition过渡 -->
      <transition enter-active-class=" animated zoomIn" leave-active-class=" animated zoomOutRight">
        <div class="mask" v-show="isShowVideo" @click.stop="isShowVideo=false">
          <video ref="v1" class="v1" :src="detailMovie.videourl" controls></video>
        </div>
      </transition>
    </page-view>
  </transition>
</template>

<script>
import MHeader from "../components/MHeader.vue";
import { mapActions } from "vuex";
export default {
  name: "Detail",
  data() {
    return {
      id: null,
      detailMovie: null,
      isShowAll: false,
      isShowVideo: false
    };
  },
  watch: {
    //观察这个视频是否有隐藏，如果有隐藏，我们就把它暂停掉
    isShowVideo(newValue) {
      if (!newValue) {
        this.$refs.v1.pause();
      }
    }
  },
  async created() {
    this.showLoading();
    this.id = this.$route.query.id;
    let resp = await this.$http.get(
      `/maoyanApi/ajax/detailmovie?movieId=` + this.id
    );
    this.detailMovie = resp.data.detailMovie;
    this.hideLoading();
  },
  methods: {
    ...mapActions(["showLoading", "hideLoading"])
  },
  components: {
    MHeader
  }
};
</script>

<style lang="scss" scoped>
.detail {
  background-color: #f4f4f4;
}
.movieBox {
  display: flex;
  box-sizing: border-box;
  padding: 0.08rem;
  position: relative;
  overflow: hidden;
  z-index: 1;
  // 背景图
  .bgImg {
    position: absolute;
    left: 0px;
    top: 0px;
    width: 100%;
    height: 100%;
    filter: blur(30px);
    z-index: -1;
  }
  .left {
    width: 2rem;
    position: relative;
    img {
      width: 100%;
      height: auto;
      display: block;
    }
    .iconfont {
      position: absolute;
      right: 0.1rem;
      bottom: 0.1rem;
      color: white;
      font-size: 0.6rem;
    }
  }
  .center {
    flex: 1;
    margin: 0;
    padding: 0;
    list-style-type: none;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    font-size: 0.24rem;
    margin-left: 0.08rem;
    color: white;
    .nm {
      font-size: 0.4rem;
      font-weight: bold;
    }
    .sc {
      span {
        color: orange;
        font-size: 0.4rem;
        font-weight: bold;
      }
    }
  }
  .right {
    width: 1.4rem;
    display: flex;
    justify-content: center;
    align-items: center;
    color: white;
    font-weight: bold;
  }
}
.btnBuyDiv {
  box-sizing: border-box;
  padding: 0.16rem 0.08rem;
  .btnBuy {
    background-color: #e54847;
    border: none;
    border-radius: 0.1rem;
    height: 0.7rem;
    font-size: 0.3rem;
    color: white;
    width: 100%;
    outline: none;
  }
}
.dra {
  background-color: white;
  font-size: 0.28rem;
  box-sizing: border-box;
  padding: 0.08rem;
  line-height: 1.8;
  text-indent: 2em;
  &.hide {
    overflow: hidden;
    max-height: 4em;
  }
}
.upAndDown {
  display: flex;
  justify-content: center;
  align-items: center;
  border-bottom: 1px solid lightgray;
  background-color: white;
  height: 0.6rem;
  .iconfont {
    &.up {
      transform: rotateZ(180deg);
    }
  }
}
.mask {
  position: fixed;
  left: 0px;
  top: 0px;
  right: 0px;
  bottom: 0px;
  background-color: rgba(0, 0, 0, 0.7);
  z-index: 9998;
  display: flex;
  justify-content: center;
  align-items: center;
  .v1 {
    width: 100%;
    height: auto;
  }
}
</style>